/*
 * Copyright 2009 XueSong Guo.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.webwheel.template;

/**
 * 模板组件渲染异常类。
 */
public class RenderException extends RuntimeException {

    private String exp;
    private boolean expNullPointer;

    public RenderException(String exp, Throwable cause) {
        super("Exception while rendering: " + exp, cause);
        setStackTrace(new StackTraceElement[0]);
        this.exp = exp;
        if (cause != null && cause.getStackTrace().length > 0 && cause.getStackTrace()[0].getClassName() != null && cause.getStackTrace()[0].getClassName().startsWith("cn.webwheel.gen.ComponentRenderer_")) {
            expNullPointer = true;
        }
    }

    /**
     * 获得出现异常的页面模板表达式。
     * @return 模板表达式
     */
    public String getExpression() {
        return exp;
    }

    /**
     * 返回是否是表达式对象级联中出现的空指针错误，不表示表达式函数内部出现的空指针错误。
     * @return 是否是空指针错误
     */
    public boolean isExpNullPointer() {
        return expNullPointer;
    }
}
